//
//  KDLibrary.h
//  Source List
//
//  Created by Keith Duncan on 05/03/2008.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class KDLibrary, SourceNode;

NS_INLINE BOOL FileExistsAtPath(NSString *path) {
	return (path != nil && ![path isEmpty] && [[NSFileManager defaultManager] fileExistsAtPath:[path stringByExpandingTildeInPath]]);
}

extern NSString *const KDLibraryUnknownLocation;

// This is used for converting KDLibrary subclasses to NSMenu
@protocol KDLibraryDelegate <NSObject, AFBundleDiscovery>
- (void)requestPathForLibrary:(KDLibrary *)library;
@optional
// Root children are NEVER selectable and you won't be queried
- (BOOL)library:(KDLibrary *)library isObjectSelectable:(id)object;
@end

/*!
    @class
    @abstract    This is an abstract class for loading XML library representations, iTunes, iPhoto, perhaps even your custom store
*/

@interface KDLibrary : NSObject {
	id <KDLibraryDelegate> delegate;
	
	BOOL _loaded;
	
	id _library;
	NSString *_path;
	
	SourceNode *_rootNode;
}

// init with KDLibraryUnknownLocation to trigger an immediate request
- (id)initWithFilePath:(NSString *)path;

@property(copy) NSString *path;

@property(assign) id <KDLibraryDelegate> delegate;

- (BOOL)isLoaded;

- (BOOL)loadAndReturnError:(NSError **)error;

@property(retain, readonly) SourceNode *rootNode;

// This should really be a subclass specific function

- (NSMenu *)sourceMenu;

@end

// Subclasses must also conform to this protocol

@protocol KDLibraryDiscovery
- (NSString *)name;
- (NSString *)expectedPath;
@optional
- (NSArray *)additionalSearchPaths;
@end
